// 设置 div 高度对齐 图片自动居中
function refresh() {
    for (let i = 1; i <= 5; ++ i) {
        if (document.getElementsByClassName("auto-center-src-" + i).length === 0) break;
        const src = $('.auto-center-src-' + i);
        const padding = src.css("padding-left").replace('px', '');
        $('.auto-center-target-' + i).css("height", src.height() + 2*padding);
    }
}
refresh();
window.addEventListener('resize', refresh);

L2Dwidget.init({
    "model": {
        "jsonPath": "https://unpkg.com/live2d-widget-model-wanko@1.0.5/assets/wanko.model.json",
        "scale": 1
    },
    "display": {
        "position": "left",
        "width": 150,
        "height": 300,
        "hOffset": -20,
        "vOffset": -150
    },
    "mobile": {
        "show": true,
        "scale": 0.5
    },
    "react": {
        "opacityDefault": 0.7,
        "opacityOnHover": 0.2
    }
});

function copyToClipboard(str) {
    let put = document.createElement('textarea'); // 动态创建textarea元素
    put.value = str; // 把需要复制的内容赋值到textarea的value上

    put.setAttribute('readOnly', 'true');
    // 注意大小写，不写的话手机端会自动弹出输入框

    document.body.appendChild(put); // 把创建的textarea元素添加进body元素内
    put.select(); // 选择对象
    document.execCommand("Copy"); // 执行浏览器复制命令
    put.className = 'oInput';
    put.style.display = 'none';
    put.style.opacity = '0';
    cocoMessage.success('复制成功')
}